package com.gec.filter;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public abstract class BaseFilter implements Filter {
	private FilterConfig config;

	@Override
	public void init(FilterConfig config) throws ServletException {
		this.config = config;
		init();
	}

	protected void init() {
	}

	@Override
	public void destroy() {
	}

	public String getInitParameter(String key) {
		return this.config.getInitParameter(key);
	}

	@Override
	public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain)
			throws IOException, ServletException {
		HttpServletRequest _req = (HttpServletRequest) req;
		HttpServletResponse _resp = (HttpServletResponse) resp;
		doFilter(_req, _resp, chain);
	}

	// {1}必须让子类来定义过滤规则。{来实现它}
	protected abstract void doFilter(HttpServletRequest req, HttpServletResponse resp, FilterChain chain)
			throws IOException, ServletException;

}
